package com.yunhuajinfu.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by ekikousei易皇星 on 16/11/22.
 * E-mail:13764664731@163.com
 * Signature:缘分是本书,翻的不经意会错过,读的太认真会流泪!!
 * <p/>
 * TODO:类描述:  viewpager  滑动fragment懒加载
 */
public abstract class LazyFragment extends Fragment {
    protected View mRootView;
    public Context mContext;
    protected boolean isPrepared;      ////标志位，子类View已经初始化完成。
    private  boolean isfirstVisible=true;


    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        Log.i("tag==","setUserVisibleHint");
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            if(isfirstVisible){
                firstVisiblegetData();
                isfirstVisible=false;
            }else {
            }

        }
    }
    public boolean isfirstVisible() {
        return isfirstVisible;
    }

    public void setIsfirstVisible(boolean isfirstVisible) {
        this.isfirstVisible = isfirstVisible;
    }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        Log.i("tag==","onCreate");
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        setHasOptionsMenu(true);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.i("tag==","onCreateView");
        if (mRootView == null) {
            mRootView = initView();
        }
        return mRootView;
    }

    public abstract View initView();

    public abstract void initData();

    public  abstract  void firstVisiblegetData();

    @Override
    public void onDestroyView() {
        Log.i("tag==","onDestroyView");
        super.onDestroyView();
        mRootView=null;
    }

    @Override
    public void onDestroy() {
        Log.i("tag==","onDestroy");
        super.onDestroy();
    }
}
